#!/usr/bin/env bash
dt="`date -d "$d  0 days ago "  "+%Y-%m-%d"`"
mysql -uroot -proot -hhadoop2<<EOF
use oracleanditem;
select RECORDTIME
,sum(case when TRADE_TYPE= '103' then abs(AMOUNT) else 0 end)/100 AS getCredits
,SUM(case when TRADE_TYPE= '155' or TRADE_TYPE='158' then abs(AMOUNT) else 0 end)/100 as usedCredits
from TBL_TRADE
where RECORDTIME='$dt'
group by RECORDTIME;
EOF